/* GLTexture.h
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <graphics/SDLSurface.h>
#include <graphics/GLVertexData.h>
#include <graphics/GLVertexDataLocal.h>

#ifndef GLTEXTURE_H_
#define GLTEXTURE_H_

class GLTexture
{
	int id;
	SDLSurface rawSurface;
	unsigned int elementWidth;
	unsigned int elementHeight;
	unsigned int elementCountX;
	unsigned int elementCountY;
	double ratioX;
	double ratioY;
	unsigned int pitch;
	GLVertexData<vector2d>* textureVertices;

public:
	typedef enum _GLTexCoord
	{
		TEX_BOTTOM 	= 0x01,
		TEX_TOP 	= 0x02,
		TEX_LEFT 	= 0x10,
		TEX_RIGHT	= 0x20,
		TEX_BL 		= 0x11,
		TEX_BR		= 0x21,
		TEX_TL		= 0x12,
		TEX_TR		= 0x22
	} GLTexCoord;

public:
	GLTexture(SDLSurface& s, unsigned int eWidth, unsigned int eHeight);
	GLTexture(SDL_Surface* s, unsigned int eWidth, unsigned int eHeight);
	GLTexture(SDLSurface& s, unsigned int eWidth, unsigned int eHeight,
		GLVertexData<vector2d>* verticesObject);
	GLTexture(SDL_Surface* s, unsigned int eWidth, unsigned int eHeight,
		GLVertexData<vector2d>* verticesObject);

	double getCoordX(GLTexCoord corner, unsigned int element);
	double getCoordY(GLTexCoord corner, unsigned int element);
	vector2d getCoord(GLTexCoord corner, unsigned int element);

	void texCoord2d(GLTexCoord corner, unsigned int element);

	void load();
	void use();
	int getId() { return id; }
	GLVertexData<vector2d>* getTextureVertices() { return textureVertices; }
	int getElementHeight() { return elementHeight; }
	int getElementWidth() { return elementWidth; }

private:
	void initVertices();
};

#endif /* GLTEXTURE_H_ */
